package com.xnyzc.lhy.mis.controller.cmsapi.coupon;


import com.xnyzc.lhy.common.entity.CouponRv;
import com.xnyzc.lhy.common.exception.CouponException;
import com.xnyzc.lhy.common.penum.coupon.CouponErrorCode;
import com.xnyzc.lhy.mis.entity.coupon.CouponInfoSearchResult;
import com.xnyzc.lhy.mis.service.coupon.IOaSysCouponInfoService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author haoyfa
 * @since 2019-12-16
 */
@RestController
@RequestMapping("/coupon/couponInfo")
@Slf4j
public class OaSysCouponInfoController {

    @Autowired
    IOaSysCouponInfoService iOaSysCouponInfoService;

    /**
     * 获取优惠券发放记录
     *
     * @return
     */
    @ApiOperation(value = "获取优惠券发放记录", notes = "获取优惠券发放记录")
    @GetMapping(value = "/queryCouponInfoList")
    public CouponRv queryCouponInfoList(@RequestParam("batchId") String batchId) {
        try {
            List<CouponInfoSearchResult> couponInfoSearchResultList = iOaSysCouponInfoService.queryCouponInfoList(batchId);
            return CouponRv.wrapSuccess(couponInfoSearchResultList);
        }
        catch (CouponException ae){
            log.error("获取优惠券发放记录 失败：" + ae.getErrno().getDesc());
            return CouponRv.wrapErrorCode(ae.getErrno());
        }
        catch (Exception ex){
            log.error("获取优惠券发放记录 失败：" + CouponErrorCode.unKnow.getDesc());
            return CouponRv.wrapErrorCode(CouponErrorCode.unKnow);
        }
    }
}
